package leetcode;

import javax.swing.tree.TreeNode;

public class Solution7 {
    public int minDepth(TreeNode root) {
        if(root == null){
            return 0;
        }

        int leftHigh = minDepth(root.left);
        int rightHigh = minDepth(root.right);

        if(root.left == null && root.right != null){
            return 1 + rightHigh;
        }
        if(root.left != null && root.right == null){
            return 1 + leftHigh;
        }

        //左右子树都不为空
        int result = 1 + Math.min(leftHigh,rightHigh);
        return result;
    }
}
